package com.xzy;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.*;

/**
 * @author xzy.xiao
 * @date 2022/8/10  11:13
 */
public class Main {
    public static void main(String[] args) throws SQLException, IOException {
        // DataSource dataSource = ShardingConfig.configWithJava();
        DataSource dataSource = ShardingConfig.configWithYaml();
        String sql = "INSERT INTO tbl_order(order_no,user_no,create_time) value (?,?,?)";

        try (
                Connection connection = dataSource.getConnection();
                PreparedStatement preparedStatement = connection.prepareStatement(sql)
        ) {
            for (int orderNo = 0; orderNo < 100; orderNo++) {
                for (int userNo = 0; userNo < 100; userNo++) {
                    Timestamp createTime = new Timestamp(System.currentTimeMillis());
                    preparedStatement.setInt(1, orderNo);
                    preparedStatement.setInt(2, userNo);
                    preparedStatement.setTimestamp(3, createTime);
                    System.out.printf("orderNo=%d,userNo=%d,createTime=%s\n", orderNo, userNo, createTime);
                    preparedStatement.execute();
                }
            }
        }
    }
}
